package account;

import utils.SessionVar;
import utils.Var;

import javax.servlet.http.HttpSession;

/**
 * Created by IntelliJ IDEA.
 * User: Shawn
 * Date: 2009-7-22
 * Time: 21:49:28
 */
public class AccountUtils {

    public static boolean isAdmin(HttpSession session) {
        String account = (String) session.getAttribute(SessionVar.USER_ACCOUNT);
        return account.equals(Var.ADMIN_ACCOUNT);
    }

    public static boolean hasRight(HttpSession session, int right) {
        long rights = (Long) session.getAttribute(SessionVar.USER_RIGHTS);
        return (rights & right) != 0;
    }

    public static boolean hasControlExamineeRight(HttpSession session) {
        long rights = (Long) session.getAttribute(SessionVar.USER_RIGHTS);
        return (rights & (Var.RIGHT_CONTROL_EXAMINEE | Var.RIGHT_CONTROL_EXAMINEE_3_TIME | Var.RIGHT_CONTROL_EXAMINEE_NO_LIMIT)) != 0;
    }
}
